<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */

require_once("cms/core/helper/Abstract.php");
require_once("cms/core/om/LanguagePeer.php");

class PHP_CMS_View_Helper_List_Panel extends PHP_CMS_View_Helper_Abstract {

    function panel($toNew = null, $form, $fields=array(), $languages=true) {

        // Save a token
        require_once("mvc/util/TokenProcessor.php");
        $token = TokenProcessor::getInstance();
        $token->saveToken($this->pageContext->request);

?>
    <div>
        <input type="hidden" name="order" value="<?=$form->getOrder()?>" />
        <input type="hidden" name="direction" value="<?=$form->getDirection()?>" />
        <input type="hidden" name="page" value="<?=$form->getPage()?>" />
        <input type="hidden" name="id" value="<?=$form->getId()?>" />
        <input type="hidden" name="action" value="<?=$form->getAction()?>" />
        <input type="hidden" name="<?=MVC::TOKEN_KEY?>" value="<?=$this->pageContext->request->getSession()->getAttribute(MVC::TRANSACTION_TOKEN_KEY)?>" />
    </div>

    <div class="ctrl" style="line-height:25px;">

        <? if(!is_null($toNew)) { ?>
            <input class="button" type="button" name="new"
                   value="<?=$this->message("button.new", _Core::BUNDLE)?>"
                   onclick="to('<?=$toNew?>')"
                   title="<?=$this->message("title.new", _Core::BUNDLE)?>" /> &nbsp;|&nbsp;
        <? } ?>


        <?=$this->message("label.search", _Core::BUNDLE)?> :
        <input class="panel" type="text" name="query" value="<?=$form->getQuery()?>" onkeydown="this.form.page.value=0" title="<?=$this->message("title.search", _Core::BUNDLE)?>" />

        &nbsp;|&nbsp;

        <?=$this->message("label.fields", _Core::BUNDLE)?> :
        <select name="filter" onchange="this.form.page.value=0" title="<?=$this->message("title.filter.fields", _Core::BUNDLE)?>" class="panel">
            <option value=""><?=$this->message("choose.all", _Core::BUNDLE)?></option>
            <? foreach(array_keys($fields) as $key) { ?>
            <option value="<?=$key?>" <?=$form->getFilter() == $key ? " selected=\"selected\"" : ""?>><?=$fields[$key]?></option>
            <? } ?>
        </select>

        &nbsp;|&nbsp;

        <? if($languages && $this->param(_Core::I18N)) { ?>

            <?=$this->pageContext->message("label.languages", _Core::BUNDLE)?>:
            <select name="language" onchange="this.form.page.value=0" title="<?=$this->message("title.filter.language", _Core::BUNDLE)?>"  class="panel">
                <option value=""<?=$form->getLanguage() == "" ? " selected=\"selected\"" : ""?>><?=$this->message("choose.all", _Core::BUNDLE)?></option>
                <? foreach(LanguagePeer::getI18n() as $language): ?>
                    <option value="<?=$language->getCode()?>"<?=$form->getLanguage() == $language->getCode() ? " selected=\"selected\"" : ""?>><?=$language->getName()?></option>
                <? endforeach; ?>
            </select>

            &nbsp;|&nbsp;

        <? } ?>

        <?=$this->pageContext->message("label.results-per-page", _Core::BUNDLE)?>:
        <select name="results" onchange="this.form.page.value=0" title="<?=$this->message("title.filter.results", _Core::BUNDLE)?>">
            <option value="10"<?=$form->getResults() == "10" ? " selected=\"selected\"" : ""?>>10</option>
            <option value="20"<?=$form->getResults() == "20" ? " selected=\"selected\"" : ""?>>20</option>
            <option value="30"<?=$form->getResults() == "30" ? " selected=\"selected\"" : ""?>>30</option>
            <option value="40"<?=$form->getResults() == "40" ? " selected=\"selected\"" : ""?>>40</option>
            <option value="50"<?=$form->getResults() == "50" ? " selected=\"selected\"" : ""?>>50</option>
            <option value="100"<?=$form->getResults() == "100" ? " selected=\"selected\"" : ""?>>100</option>
            <option value=""<?=$form->getResults() == "" ? " selected=\"selected\"" : ""?>><?=$this->message("choose.all", _Core::BUNDLE)?></option>
        </select>

        &nbsp;|&nbsp;

        <input type="button" value="<?=$this->message("button.clear", _Core::BUNDLE)?>"
               class="button" onclick="clean('<?=get_class($form)?>')"
               title="<?=$this->message("title.filter.clear", _Core::BUNDLE)?>" />

        &nbsp;|&nbsp;

        <input type="submit" value="<?=$this->message("button.search", _Core::BUNDLE)?>" class="button" />

    </div><?

    }

}
?>
